Skip to content

Add cleanup of old account events #6576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025

Conversation

smithellis
Copy link
Contributor

This commit implements a data cleanup feature for account events:

  • Adds migration to perform initial cleanup of account events older than 2 years
  • Adds management command 'cleanup_old_account_events' for periodic cleanup
  • Can be scheduled via crontab to run daily

The cleanup can be run manually with:
python manage.py cleanup_old_account_events

This .delete()[0] is an interesting thing I learned - delete returns a tuple.

  • The first item (index [0]) is the total number of objects deleted
  • The second item (index [1]) is a dictionary that breaks down the number of deletions per object type

This commit implements a data cleanup feature for account events:
- Adds migration to perform initial cleanup of account events older than 2 years
- Adds management command 'cleanup_old_account_events' for periodic cleanup
- Can be scheduled via crontab to run daily

The cleanup can be run manually with:
python manage.py cleanup_old_account_events
Copy link
Collaborator

@akatsoulas akatsoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add the cron entry to run once per week. r+wc



def delete_old_account_events(apps, schema_editor):
AccountEvent = apps.get_model('users', 'AccountEvent')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep this code DRY and have a single place where we delete accounts, you can use the call_command function to call the management command that you wrote

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from datetime import timedelta


def delete_old_account_events(apps, schema_editor):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's match the name with the one of the management command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@smithellis smithellis merged commit 9624eb3 into mozilla:main Mar 20, 2025
2 checks passed
@smithellis smithellis deleted the remove-aged-account-events branch March 20, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants